home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c,alt.msdos.programmer
- Subject: Re: Two strange C problems.
- Date: 7 Jan 1996 21:42:42 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4cq3ri$amp@solutions.solon.com>
- References: <4cojb2$qog@lugb.latrobe.edu.au> <4cq1vu$d8c@gryphon.phoenix.net>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4cq1vu$d8c@gryphon.phoenix.net>,
- Bruce Wedding <brucew@phoenix.net> wrote:
- >cs102238@lux.latrobe.edu.au (Gregary John Boyles ) wrote:
- >>PROBLEM 2 :
-
- >>const escape=27;
- >>const cr=13;
- >>const bs=8;
-
- >In C++, this is ok. In C, you have to use:
- >#define ESC 27
- >#define CR 13
-
- This is untrue.
-
- Rather, it would be true if you wanted to use escape, cr, or bs as sizes
- for array variables, initializers of static or global variables, as case
- values, or in other contexts where a constant is required. It appears
- to have nothing to do with the problem at hand.
-
- >etc.
-
- >>while (ch!=cr)
- >Then all these loops will work.
-
- This would work with cr being a variable, as well, even if it's not a
- const - in fact, the poster specifically *said* that that worked.
-
- >>If I replace the 27 with \27' or the 13 with '\13' then these loops don't
- >>work i.e. an infinite loop results. WHY?
-
- >Because the character will never equal those values, simple enough.
-
- But that doesn't explain the problem, which is that \27 is 27 *OCTAL*,
- not decimal, and is 23 decimal, which is ASCII ETB, not ESC. Ditto
- CR/VT.
-
- >It uses the standard ASCII character set, at least in DOS. If you
- >want to print those characters, just use those values. The \
- >character is only used with the following chars ( ",\,n,r,f,0). Well,
- >that is probably not all of them, but those are the most important.
- >If you want to print those characters above, do this:
-
- You seem to have totally missed the point; \ is used with a large set of
- things. To put generic characters in with it, you can use \xhex-number or
- \octal-number. The \0 is a special case of \octal-number, and means,
- specifially, the character whose value is 0, base 8. Conveniently, 0
- in octal is 0 in decimal.
-
- >I hate to say it, but you are asking for it. Maybe one needs to learn
- >the damn language so they can program sensibly and predictably. At
- >least there is a standard for C. Pascal has no standard and will
- >behave VERY unpredictably from system to system.
-
- This is actually correct, however, you yourself should learn it a bit
- more. (Although I admit, I'd rather you err, as you have, on the side
- of caution, than on the side of overconfidence.)
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1995 Peter Seebach.
- C/Unix proto-wizard -- C/Unix questions? Send mail for help. No, really!
- Using trn? Weird new newsgroup problem? I know the fix! Email me!
- The *other* C FAQ - ftp taniemarie.solon.com /pub/c/afq - Not A Flying Toy
-